﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;
using System.Text;

namespace WebSite.Phone
{
    public partial class User : PreBasePage
    {
        private string userid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            userid = Request.QueryString["id"] + "";

            if (!Page.IsPostBack)
            {
                BindBlogType();
                BindUser();
                LoadContent();
            }
        }

        #region 加载类别
        private void BindBlogType()
        {
            BlogTypeHelper bthelper = new BlogTypeHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "Flag", 0);
            c.Add(CriteriaType.Equals, "BlogBigType", "图文");
            DataTable dtBlogType = bthelper.QueryBlogTypeBySearchToTable(c, new Order[] { new Order("CreateDate", OrderMode.Desc) }, 0, 10, null);

            rptBlogType1.DataSource = dtBlogType;
            rptBlogType1.DataBind();

            rptBlogType2.DataSource = dtBlogType;
            rptBlogType2.DataBind();
        }
        #endregion

        #region 加载用户信息
        private void BindUser()
        {
            Users uinfo = new Users();
            UsersHelper uhelper = new UsersHelper();
            uinfo = uhelper.GetUsers(userid);
            litNickName.Text = uinfo.NickName;
        }
        #endregion

        #region 加载用户博客列表
        private void LoadContent()
        {
            //设置控件属性，从BasePage中得到
            PageConfig(BlogUPager);

            BlogHelper bhelper = new BlogHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "Flag", 0);
            c.Add(CriteriaType.Equals, "UsersID", userid);
            c.Add(CriteriaType.Equals, "BlogBigType", "图文");

            BlogUPager.ItemCount = bhelper.QueryBlogCountBySearch(c);

            // 以下的值从BasePage中得到
            BlogUPager.UrlFormat = UrlFormat;

            string[] fields = new string[] { "ID", "BlogBigType", "Title", "HasPic", "Flag", "CreateDate" };
            DataTable dtBlog = bhelper.QueryBlogBySearchToTable(c, new Order[] { new Order("CreateDate", OrderMode.Desc) }, BlogUPager.Begin - 1, BlogUPager.Count, fields);

            if (dtBlog != null && dtBlog.Rows.Count > 0)
            {
                foreach (DataRow drblog in dtBlog.Rows)
                {
                    string blogid = drblog["ID"] + "";
                    string title = drblog["Title"] + "";
                    string strtitle = "";
                    strtitle = Tools.GetFirstString(title, 32);
                    //判断是否存在图片
                    string haspic = drblog["haspic"] + "";
                    if (haspic == "1")
                    {
                        strtitle += "(图)";
                    }
                    drblog["Title"] = strtitle;
                }
            }

            rptBlog.DataSource = dtBlog;
            rptBlog.DataBind();
        }
        #endregion
    }
}